//package com.rbac.service.test.impl;
//
//import com.common.Result;
//import com.common.utils.JwtUtil;
//import com.domain.dto.login.LoginDto;
//import com.domain.dto.test.RegisterDto;
//import com.domain.vo.test.LoginSuccessVo;
//import com.rbac.exception.CommonException;
//import com.rbac.mapper.test.EmployeeMapper;
//import com.rbac.mapper.test.LoginMapper2;
//import com.rbac.pojo.Employee;
//import com.rbac.service.test.LoginService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Service;
//
//import java.util.HashMap;
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
//@Service
//public class LoginServiceImpl implements LoginService {
//
//    @Autowired
//    private LoginMapper2 loginMapper2;
//    @Autowired
//    private EmployeeMapper employeeMapper;
//
//    @Autowired
//    private StringRedisTemplate redisTemplate;
//    @Autowired
//    private PermissionServiceImpl permissionService;
//
//    @Override
//    public LoginSuccessVo login(LoginDto loginDto) {
//        System.out.println(loginDto);
//        Employee employee = loginMapper2.getUserbyName(loginDto.getUsername());
//        if(employee == null ){
//            throw new CommonException("查询结果为空");
//        }
//        if(!employee.getPassword().equals(loginDto.getPassword())){
//            throw new CommonException("密码错误，请重新输入");
//        }
//
//        //生成jwt密钥
//        Map<String, Object> claim = new HashMap<>();
//        claim.put("id",employee.getId());
//        claim.put("username", employee.getUsername());
//        String token = JwtUtil.genToken(claim);
////        String key = "Jwt:" + token;
////        System.out.println("生成的token为："+key);
//        redisTemplate.opsForValue().set(token,token,1, TimeUnit.HOURS);
//
//        LoginSuccessVo loginSuccessVo =new LoginSuccessVo();
//        //TODO 登录用户信息
////        loginSuccessVo.setEmployee(employee);
//        loginSuccessVo.setToken(token);
//
//        return loginSuccessVo;
////        Employee employee = loginMapper.getUserbyName(username);
////        if(employee == null){
////            throw new CommonException("查询用户为空");
////        }
////        if(!employee.getPassword().equals(password)){
////            throw new CommonException("密码错误，请重新输入");
////        }
////        //将数据保存到redis中
////        String jwt = "114514";
//////        redisTemplate.opsForValue().set("jwt:"+jwt, username);
////
////        return Result.success("登录成功");
//
//    }
//
//
//    @Override
//    public Result getRouter(Integer userId) {
//        return Result.success(permissionService.getTreeMenu(userId));
//    }
//
//    @Override
//    public void register(RegisterDto registerDto) {
//        String username = registerDto.getUsername();
//        String password = registerDto.getPassword();
//        String rePassword = registerDto.getRePassword();
//
//        //判断两次输入的密码是否重复
//        if(!password.equals(rePassword)){
//            throw new CommonException("两次输入的密码不一致");
//        }
//        //账号密码是否符合规则
//
//        //判断新添加的用户名是否重复
//        Employee employee = employeeMapper.getEmployeeByUsername(username);
//        if(employee != null ){
//            throw new CommonException("用户名已存在");
//        }
//        //保存新用户
//        Employee addEmployee = new Employee();
//        addEmployee.setUsername(username);
//        addEmployee.setPassword(password);
//        loginMapper2.registerUser(addEmployee);
//        System.out.println(addEmployee);
//        //给新添加的用户普通用户的角色
//        loginMapper2.setUserDefaultRole(addEmployee.getId());
//
//    }
//
//
//
////    @Autowired
////    private StringRedisTemplate redisTemplate;
////    @Override
////    public Result code() {
////
////    }
////
////    @Override
////    public Result check(String key, String code) {
////
////    }
//}
